package com.kaili.basic.controller.web.v1;

import com.baomidou.mybatisplus.plugins.Page;
import com.kaili.basic.pojo.dto.WmsReceivableHandleDetailQueryDTO;
import com.kaili.basic.pojo.entity.WmsReceivableHandleDetailEntity;
import com.kaili.basic.pojo.vo.WmsReceivableHandleDetailVO;
import com.kaili.basic.service.FinanceBookKeepingService;
import com.kaili.basic.version.ApiVersion;
import com.kaili.common.exception.RestException;
import com.kaili.common.response.CommonStatus;
import com.kaili.common.response.RestStatus;
import com.kaili.common.util.ExcelUtil;
import com.kaili.common.util.LoginDetailUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@RestController
@ApiVersion(1)
@RequestMapping("/{api_version}")
@Api(tags = "财务记账管理", description = "财务记账管理")
public class FinanceBookKeepingController {

    @Autowired
    private FinanceBookKeepingService financeBookKeepingService;

    @GetMapping("/financeBookKeeping/code")
    @ApiOperation(value = "查询流水号号")
    public Long queryStoreOrderNo(){
        return financeBookKeepingService.queryStoreOrderNo();
    }

    @PostMapping("/financeBookKeeping")
    @ApiOperation(value = "新增财务记账")
    public RestStatus addInStore(@RequestBody WmsReceivableHandleDetailEntity detail){
        detail.setCreateTime(new Date());
        detail.setCreateBy(LoginDetailUtils.getCurrentEmployeeId().longValue());
        financeBookKeepingService.insert(detail);
        return CommonStatus.ADD_OK;
    }

    @GetMapping("/financeBookKeeping")
    @ApiOperation(value = "分页查询财务记账")
    public Page<WmsReceivableHandleDetailVO> queryPageList(@ModelAttribute WmsReceivableHandleDetailQueryDTO queryDto){
        return financeBookKeepingService.queryPageList(new Page<WmsReceivableHandleDetailVO>(queryDto.getPage(),queryDto.getPageSize()),queryDto);
    }

    @GetMapping("/financeBookKeeping/export")
    @ApiOperation(value = "财务记账导出")
    public void export(HttpServletResponse response, @ModelAttribute WmsReceivableHandleDetailQueryDTO queryDto) throws RestException {
        List<WmsReceivableHandleDetailVO> list = financeBookKeepingService.queryPageList(queryDto);
        ExcelUtil.exportExcel(list,"财务记账管理","sheet1", WmsReceivableHandleDetailVO.class, UUID.randomUUID().toString()+".xls",response);
    }

}

